from django.db import models


# Create your models here.
class MyPrimary(models.Model):
    num = models.BigAutoField(verbose_name="主键", primary_key=True)
    title = models.CharField(verbose_name="标题", max_length=20, )

    def __str__(self):
        return self.title

class Manufacturer(models.Model):
    """
    一对多：一方
    """
    name = models.CharField(verbose_name="制造商名字", max_length=30)

    def __str__(self):
        return self.name

class Car(models.Model):
    """
    一对多：多方
    关系字段：外键需要定义在多方
    """
    name = models.CharField(verbose_name="名字", max_length=30)
    manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)


class Topping(models.Model):
    name = models.CharField(verbose_name="馅料名", max_length=20)


class Pizza(models.Model):
    name = models.CharField(verbose_name="披萨", max_length=20)
    toppings = models.ManyToManyField(Topping)
